﻿using AutoMapper;
using B.S.Data.MES.API.Applications.GanttchartApplication.Command;
using B.S.Domain.Dto.EorkOrderDTO;
using B.S.Domain.Ticket;
using B.S.Infratrctrue;
using B.S.Requst;
using MediatR;

namespace B.S.Data.MES.API.Applications.GanttchartApplication.CommandHandler
{
    public class WorkOrderQueryCommandHandler : IRequestHandler<WorkOrderQueryCommand, APIRequst<List<WorkOrderDTOs>>>
    {
        public WorkOrderQueryCommandHandler(IBaseRepository<WorkOrder> _workorderRepository)
        {
            WorkorderRepository = _workorderRepository;
        }

        public IBaseRepository<WorkOrder> WorkorderRepository { get; }

        public async Task<APIRequst<List<WorkOrderDTOs>>> Handle(WorkOrderQueryCommand request, CancellationToken cancellationToken)
        {
            var apiResult = from a in WorkorderRepository.GetAll()
                           .Where(a => a.States == 8)
                            select new WorkOrderDTOs
                            {
                                StartTime = a.StartTime,
                                EndTime = a.EndTime,
                                States = a.States,
                                WorkCode = a.WorkCode,
                            };
            return new APIRequst<List<WorkOrderDTOs>>
            {
                Code = RequstCode.成功,
                Msg = "",
                Data = apiResult.ToList()
            };
            

        }
    }
}
